package com.ct.ecommerce.framework.core.response;

import java.io.Serializable;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author changtong
 * @since 2021/6/2
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class PageUI<T> implements Serializable {


    private List<T> records;

    /**
     * 总页数
     */
    private Long total;


    /**
     * 第几页
     */
    private Integer page;

    /**
     * 每页多少条
     */
    private Integer rows;

    /**
     * 总页数
     * @return
     */
    public long getPages() {
        if (rows == 0) {
            return 0L;
        }
        long pages = getTotal() / rows;
        if (total % rows != 0) {
            pages++;
        }
        return pages;
    }


}
